import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		rows:{},
		// 提交表单列表
		formData : [
			{ label: '外包单位',				name: 'outsourcing_company_code', 	full:true, 	required:true, type: 'select', nameStr:'label' },
			{ label: '委托检验科室',			name: 'outsourcing_department_id', 	full:true, 	required:true, type: 'select', nameStr:'label' },
		]
	}
	
	submit = {}
	
	open = (param, rows) => {
		this.submit = {
			...param,
			entry_type:2, 
			outsourcing_type:2, 
			outsourcing_data: rows.map( ({ spec_code, kind_id, kind_category, parent_kind_category, parent_kind_id, kind_name, parent_kind_name }) =>{
				return { spec_code, kind_id, kind_category, parent_kind_category, parent_kind_id, kind_name, parent_kind_name }
			})
		}
		this.modal.open()
		this.getModalSelect()
	}
	// 获取弹框下拉
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, 'outsourcing_company_code', ()=>{
			$cache.then( async f => {
				const _data = await f.getCache({ api: 'specimen/getOutsourcingDepartList' })
				$fn.setRow(formData, 'outsourcing_company_code', _data['outsourcing_company'])
				$fn.setRow(formData, 'outsourcing_department_id', _data['outsourcing_department'])
				this.setState({ formData })
			})
		})
	}
	
	render(){
		return FormModal.call(this,{ title:'转外包', labelWidth:'s9', width:600, api:'specimen/changeSpec2Outsourcing', isConfirm:true})
	}
}

export default Index